var t = require("../@babel/runtime/helpers/interopRequireDefault")(require("../@babel/runtime/helpers/typeof")),
  e = require("../services/baseURL.js"),
  n = require("./day.js"),
  r = function(t) {
    return (t = t.toString())[1] ? t : "0" + t;
  },
  o = function() {
    for (var t = [], e = 0; e < 36; e++) t[e] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
    return t[14] = "4", t[19] = "0123456789abcdef".substr(3 & t[19] | 8, 1), t[8] = t[13] = t[18] = t[23] = "-",
      t.join("");
  },
  i = function(t) {
    return "number" != typeof t && isNaN(Number(t)) ? t : 0 === Number(t) ? 0 : Number(t) % 100 == 0 ? Number(t) / 100 : (Number(t) / 100).toFixed(2);
  },
  a = function() {
    var t = wx.getStorageSync("m.".concat(e.NODE_ENV));
    return t || (t = {}, wx.setStorageSync("m.".concat(e.NODE_ENV), t), wx.removeStorageSync("Authorization")),
      t;
  },
  u = function(t) {
    var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : o(),
      r = a();
    r && r.Authorization ? r.Authorization.version === n && (r.Authorization = {
      value: t,
      status: !0,
      version: n
    }) : r.Authorization = {
      value: t,
      status: !0,
      version: n
    };
    wx.setStorageSync("m.".concat(e.NODE_ENV), r);
  };

module.exports = {
  formatTime: function(t) {
    var e = t.getFullYear(),
      n = t.getMonth() + 1,
      o = t.getDate(),
      i = t.getHours(),
      a = t.getMinutes(),
      u = t.getSeconds();
    return [e, n, o].map(r).join("/") + " " + [i, a, u].map(r).join(":");
  },
  setLocation: function(t) {
    var n = a();
    n.location = t, wx.setStorageSync("m.".concat(e.NODE_ENV), n);
  },
  getLocation: function() {
    return a().location;
  },
  getLocalDate: function(t, e) {
    var n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "-",
      o = t.getFullYear(),
      i = t.getMonth() + 1,
      a = t.getDate(),
      u = t.getHours(),
      c = t.getMinutes(),
      f = t.getSeconds();
    return "YYYY-MM-DD" === e ? [o, i, a].map(r).join(n) : "YYYY-MM" === e ? [o, i].map(r).join(n) : "MM-DD" === e ? [i, a].map(r).join(n) : "YYYY-MM-DD H:i:s" === e ? [o, i, a].map(r).join(n) + " " + [u, c, f].map(r).join(":") : "YYYY-MM-DD H:i" === e ? [o, i, a].map(r).join(n) + " " + [u, c].map(r).join(":") : void 0;
  },
  qs: function(t) {
    var e = [];
    for (var n in t) t[n] && e.push("".concat(n, "=").concat(t[n]));
    return e.join("&");
  },
  getUUID: o,
  fen2yuan: i,
  tfPrice: function(e) {
    var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : ["price"];
    return "object" === (0, t.default)(e) && e instanceof Array ? e = e.map(function(t) {
      return n.forEach(function(e) {
        e in t && (t[e] = i(t[e]));
      }), t;
    }) : "object" === (0, t.default)(e) ? n.forEach(function(t) {
      t in e && (e[t] = i(e[t]));
    }) : "number" != typeof e && "string" != typeof e || (e = i(e)), e;
  },
  setToken: u,
  expireToken: function() {
    wx.removeStorageSync("code"), wx.removeStorageSync("m.".concat(e.NODE_ENV));
  },
  wait: function(t) {
    return new Promise(function(e) {
      return setTimeout(e, t);
    });
  },
  getAuth: function() {
    var t = a();
    return !(!t || !t.Authorization) && t.Authorization;
  },
  getUserInfo: function() {
    var t = a();
    return !(!t || !t.userInfo) && t.userInfo;
  },
  setUserInfo: function(t) {
    var n = a();
    n.userInfo = t, wx.setStorageSync("m.".concat(e.NODE_ENV), n);
  },
  _getToken: a,
  getWxCode: function() {
    var t = a();
    return !(!t || !t.code) && t.code;
  },
  setWxCode: function(t) {
    if (t) {
      var n = a();
      n.code = t, wx.setStorageSync("m.".concat(e.NODE_ENV), n);
    }
  },
  setRefreshToken: function(t) {
    var e = a();
    e.refresh_token = t, u(e);
  },
  getOrderStatus: function(t) {
    var e = t.stage,
      n = e.stage,
      r = e.first_thumb,
      o = e.finally_thumb;
    return 1 == e.status ? "等待初审" === n ? r ? 1 : 0 : "等待复审" === n ? o ? 3 : 2 : "初审拒绝" === n ? 0 : "复审拒绝" === n ? 2 : "审核完成" === n ? 5 : 4 : -1;
  },
  timeDiff: function(t) {
    var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1,
      r = (0,
        n.dayjs)();
    if (1 == e) {
      var o = (0, n.dayjs)(t + ":00").add(30, "minute");
      return r.isBefore(o) ? o.diff(r, "minute") : "已过期";
    }
    if (2 == e) {
      var i = (0, n.dayjs)(t + ":00").hour(12).minute(0).millisecond(0).second(0).add(24, "hour");
      if (r.isBefore(i)) {
        var a = i.diff(r, "minute");
        return a < 60 ? "".concat(a, "分钟") : "".concat(Math.floor(a / 60), "小时").concat(a % 60, "分钟");
      }
      return "已过期";
    }
    return !1;
  }
};